@using OrchardCore.Workflows.Http.ViewModels;
@model HttpRequestTaskViewModel

<div class="form-group" asp-validation-class-for="Url">
    <label asp-for="Url">@T["URL"]</label>
    <input type="text" asp-for="Url" class="form-control code" />
    <span asp-validation-for="Url"></span>
    <span class="hint">@T["The URL to send the request to. Supports Liquid syntax."]</span>
</div>

<div class="form-group" asp-validation-class-for="HttpMethod">
    <label asp-for="HttpMethod">@T["HTTP Method"]</label>
    <select asp-for="HttpMethod" class="form-control">
        <option value="GET">GET</option>
        <option value="POST">POST</option>
        <option value="PUT">PUT</option>
        <option value="PATCH">PATCH</option>
        <option value="DELETE">DELETE</option>
    </select>
    <span asp-validation-for="HttpMethod"></span>
    <span class="hint">@T["The HTTP Method. For example: GET, POST, PUT, PATCH, OPTIONS, HEAD, DELETE"]</span>
</div>

<div class="form-group" asp-validation-class-for="ContentType">
    <label asp-for="ContentType">@T["Content Type"]</label>
    <select asp-for="ContentType" class="form-control">
        <option>text/plain</option>
        <option>application/x-www-form-urlencoded</option>
        <option>application/json</option>
        <option>application/xml</option>
    </select>
    <span asp-validation-for="ContentType"></span>
    <span class="hint">@T["The content type of the request body."]</span>
</div>

@*TODO: Only display Body field when appropriate for the selected HTTP method.*@
<div class="form-group" asp-validation-class-for="Body">
    <label asp-for="Body">@T["Body"]</label>
    <textarea asp-for="Body"></textarea>
    <span asp-validation-for="Body"></span>
    <span class="hint">@T["The body to send with POST, PUT and PATCH requests. With Liquid support."]</span>
</div>

<div class="form-group" asp-validation-class-for="Headers">
    <label asp-for="Headers">@T["Headers"]</label>
    <textarea asp-for="Headers"></textarea>
    <span asp-validation-for="Headers"></span>
    <span class="hint">@T["Provide additional HTTP headers, one per line. For example: Authorization: Bearer 123ABC. With Liquid support."]</span>
</div>

<div class="form-group" asp-validation-class-for="HttpResponseCodes">
    <label asp-for="HttpResponseCodes">@T["HTTP Response Codes"]</label>
    <input type="text" class="form-control" asp-for="HttpResponseCodes" />
    <span asp-validation-for="HttpResponseCodes"></span>
    <span class="hint">@T["A comma-separated list of HTTP response status codes to handle as activity outcomes. For example: 200, 404, 500"]</span>
</div>

<script asp-name="codemirror" depends-on="admin" at="Foot"></script>
<script asp-name="codemirror-mode-javascript" at="Foot"></script>
<script asp-name="codemirror-addon-display-autorefresh" at="Foot"></script>
<script asp-name="codemirror-addon-mode-simple" at="Foot"></script>
<script asp-name="codemirror-addon-mode-multiplex" at="Foot"></script>
<script asp-name="codemirror-mode-xml" at="Foot"></script>

<script asp-src="~/OrchardCore.Liquid/codemirror/liquid.js" at="Foot"></script>

<script at="Foot">
    $(function () {
        var codeMirrorOptions = {
            autoRefresh: true,
            lineNumbers: true,
            styleActiveLine: true,
            matchBrackets: true,
            mode: { name: "liquid" },
        };
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.Headers)'), codeMirrorOptions);
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.Body)'), codeMirrorOptions);
});
</script>
